package com.gzpi.hwgggh.controller;

import com.gzpi.hwgggh.entity.DWC;
import com.gzpi.hwgggh.entity.DWX;
import com.gzpi.hwgggh.entity.GGP;
import com.gzpi.hwgggh.mapper.DWCMapper;
import com.gzpi.hwgggh.mapper.DWGMapper;
import com.gzpi.hwgggh.mapper.DWXMapper;
import com.gzpi.hwgggh.mapper.GGPMapper;
import com.gzpi.hwgggh.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

/**
 * @date : 2021-04-15 16:05
 **/
@RequestMapping("/test")
@RestController
@CrossOrigin
public class TestController {

    @Autowired
    private DWXMapper dwxMapper;

    @Autowired
    private DWCMapper dwcMapper;

    @Autowired
    private DWGMapper dwgMapper;

    @Autowired
    private GGPMapper ggpMapper;

    @RequestMapping("/updateGGPBH")
    public Result updateGGPBH(){
        List<DWX> dwxes = dwxMapper.selectDWXGListBandGgpXGListAndDwtpByVo(null);
        List<DWC> dwcs = dwcMapper.selectDWCListBandGgpCListAndDwtpByVo(null);
        for (DWX dwx : dwxes) {
            String xzid = dwx.getID();
            for (GGP xzggp : dwx.getXzggps()) {
                String ggbh = xzggp.getGGBH();
                ggbh = ggbh.substring(ggbh.indexOf("_"));
                xzggp.setGGBH(xzid+ggbh);
                xzggp.setTableName("GGP_X");
                ggpMapper.updateById(xzggp);
            }
            String ghid = dwx.getDwg().getID();
            for (GGP ghggp : dwx.getGhggps()) {
                String ggbh = ghggp.getGGBH();
                ggbh = ggbh.substring(ggbh.indexOf("_"));
                ghggp.setGGBH(ghid+ggbh);
                ghggp.setTableName("GGP_G");
                ggpMapper.updateById(ghggp);
            }
        }

        for (DWC dwc : dwcs) {
            String id = dwc.getID();
            for (GGP ggp : dwc.getGgps()) {
                String ggbh = ggp.getGGBH();
                ggbh = ggbh.substring(ggbh.indexOf("_"));
                ggp.setGGBH(id+ggbh);
                ggp.setTableName("GGP_C");
                ggpMapper.updateById(ggp);
            }

        }

        return Result.createSuccess("成功");

    }

}
